package host.springboot.framework.mybatisplus.domain;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * 基础DO
 *
 * @param <ID> ID类型
 * @author JiYinchuan
 * @since 1.0.0
 */
@Data
public abstract class BaseDO<ID> implements Serializable {

    public static final String FIELD_ID = "id";
    public static final String FIELD_CREATE_TIME = "createTime";
    public static final String FIELD_CREATE_USER = "createUser";
    public static final String FIELD_UPDATE_TIME = "updateTime";
    public static final String FIELD_UPDATE_USER = "updateUser";
    public static final String FIELD_LOGIC_DELETE = "logicDelete";
    public static final String FIELD_VERSION = "version";

    /**
     * 设置ID
     *
     * @param id ID
     * @since 1.0.0
     */
    public abstract void setId(ID id);

    /**
     * 获取ID
     *
     * @return ID
     * @since 1.0.0
     */
    public abstract ID getId();

    /**
     * 创建时间
     *
     * <p>新增时将自动填充当前时间
     */
    @TableField(value = "create_time", fill = FieldFill.INSERT, insertStrategy = FieldStrategy.NOT_NULL)
    public LocalDateTime createTime;

    /**
     * 创建人
     */
    @TableField(value = "create_user", fill = FieldFill.INSERT)
    public String createUser;

    /**
     * 最后修改时间
     *
     * <p>新增与修改时自动填充当前时间
     */
    @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE,
            insertStrategy = FieldStrategy.NOT_NULL, updateStrategy = FieldStrategy.NOT_NULL)
    public LocalDateTime updateTime;

    /**
     * 最后修改时间
     */
    @TableField(value = "update_user", fill = FieldFill.INSERT_UPDATE)
    public String updateUser;

}
